package com.ruoyi.yljf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.yljf.domain.Courseware;
import com.ruoyi.yljf.mapper.CoursewareMapper;
import com.ruoyi.yljf.service.ICoursewareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 课件Service业务层处理
 *
 * @author metaee
 * @date 2025-02-14
 */
@Service
public class CoursewareServiceImpl extends ServiceImpl<CoursewareMapper, Courseware> implements ICoursewareService {

    @Autowired
    private CoursewareMapper coursewareMapper;

    /**
     * 查询课件列表
     *
     * @param courseware 课件
     * @return 课件
     */
    @Override
    public List<Courseware> selectCoursewareList(Courseware courseware) {
        LambdaQueryWrapper<Courseware> queryWrapper = Wrappers.lambdaQuery();
        if (StringUtils.isNotNull(courseware.getCourseId())) {
            queryWrapper.eq(Courseware::getCourseId, courseware.getCourseId());
        }
        if (StringUtils.isNotNull(courseware.getPackageId())) {
            queryWrapper.eq(Courseware::getPackageId, courseware.getPackageId());
        }
        if (StringUtils.isNotEmpty(courseware.getCourseware())) {
            queryWrapper.eq(Courseware::getCourseware, courseware.getCourseware());
        }
        return coursewareMapper.selectList(queryWrapper);
    }

    @Override
    public List<Courseware> queryCoursewareList(Courseware courseware) {
        List<Courseware> list = this.selectCoursewareList(courseware);
//        list.stream().map()
//        return List.of();
        return new ArrayList<>(list);
    }

    @Override
    public Courseware selectCoursewareDetail(Courseware courseware) {
        return coursewareMapper.selectOne(new LambdaQueryWrapper<>(Courseware.class)
                .eq(Courseware::getId, courseware.getId())
                .eq(Courseware::getCourseId, courseware.getCourseId())
                .eq(Courseware::getPackageId, courseware.getPackageId()));
    }
}
